rm(submodels)
plotmodels$term2 <- plotmodels$term
plotmodels$model2 <- plotmodels$model
plotmodels$term <- plotmodels$outcome
plotmodels$model <- plotmodels$term2
unique(plotmodels$term)
plotmodels <- plotmodels%>%mutate(model2 = case_when(
model == "ea" ~ "EA Original",
model == "RegType_lied_EA" ~ "LIED",
model == "RegType_RoW_EA" ~ "RoW",
model == "Politytype_Anocracy" ~ "Polity",
model == "status_fh_PF" ~ "FH",
model == "AnckarRegtype_MP_Autocracy" ~ "CPR",
model == "HTW_RegType_MP_Autocracy" ~ "ARD",
model == "RegType_magaloni_EA" ~ "AoW"))
plotmodels$model <- plotmodels$model2
plotmodels <- plotmodels%>%mutate(term2 = case_when(
term == "under5" ~ "Under-5 Mortality",
term == "infant" ~ "Infant Mortality",
term == "life" ~ "Life Expectancy",
term == "literacy_original" ~ "Literacy",
term == "schooling2" ~ "Schooling",
term == "lit_equ" ~ "Literacy Equality",
term == "school_equ" ~ "Schooling Equality"))
plotmodels$term <- plotmodels$term2
plotmodels<- plotmodels %>% mutate ( conf.low_95 = estimate - 1.96 *  std.error, conf.high_95 = estimate + 1.96 * std.error,
conf.low_90 = estimate - 1.64 *  std.error, conf.high_90 = estimate + 1.64 * std.error) %>% as_tibble()
### add regime history
indepvars <- c("ea_avg" , "dem_avg",
"RegType_lied_EA_hist", "RegType_lied_DEM_hist",
"RegType_RoW_EA_hist", "RegType_RoW_DEM_hist",
"Politytype_Anocracy_hist", "Politytype_Democracy_hist",
"status_fh_PF_hist", "status_fh_F_hist",
"HTW_RegType_MP_Autocracy_hist", "HTW_RegType_Democracy_hist",
"RegType_magaloni_EA_hist", "RegType_magaloni_DEM_hist",
"AnckarRegtype_MP_Autocracy_hist", "AnckarRegtype_Democracy_hist"
)
depvars <- c("infant", "under5", "life", "literacy_original", "schooling2", "lit_equ", "school_equ")
rxdepvars <- c("rx_infant", "rx_under5", "rx_life", "rx_literacy_original", "rx_schooling2", "rx_lit_equ", "rx_school_equ")
controls <- c("aid", "loggdp",  "gdp_grow", "gini2",  "resourcesdep_hm",
"communist", "urban_cow", "ELF", "lnpop", "violence_domestic")
a <- seq(1,15 , by = 2)
models <- list()
for (i in 1:length(depvars)) {
outcome <- depvars[i]
rx <- rxdepvars[i]
for (j in 1:8) {
print(paste0("Running Model " , outcome,"_model_",j, ", you bastard!"))
indepvar <- indepvars[c(a[j],a[j]+1)]
formula <- as.formula(paste(outcome, "~",  paste(indepvar, collapse = "+"), "+", rx, "+", paste(controls, collapse = "+")))
models[[paste0(outcome,"_model_", j)]] <- lm_robust(formula, data = df, fixed_effects = year, clusters = ccode, se_type = "stata")
}
}
submodels <- list()
for (i in 1:length(models)){
submodels[[paste0("sub_", models[i])]] <- tidy(models[[i]]) %>%
filter(term %in% c("ea_avg", "RegType_lied_EA_hist", "RegType_RoW_EA_hist", "Politytype_Anocracy_hist", "status_fh_PF_hist", "AnckarRegtype_MP_Autocracy_hist", "HTW_RegType_MP_Autocracy_hist", "RegType_magaloni_EA_hist")) %>%
mutate(model = names(models)[i])
}
plotmodels2 <- submodels %>%
rbindlist %>%
as.data.frame
rm(submodels)
plotmodels2$term2 <- plotmodels2$term
plotmodels2$model2 <- plotmodels2$model
plotmodels2$term <- plotmodels2$outcome
plotmodels2$model <- plotmodels2$term2
unique(plotmodels2$term)
plotmodels2 <- plotmodels2%>%mutate(model2 = case_when(
model == "ea_avg" ~ "EA Original",
model == "RegType_lied_EA_hist" ~ "LIED",
model == "RegType_RoW_EA_hist" ~ "RoW",
model == "Politytype_Anocracy_hist" ~ "Polity",
model == "status_fh_PF_hist" ~ "FH",
model == "AnckarRegtype_MP_Autocracy_hist" ~ "CPR",
model == "HTW_RegType_MP_Autocracy_hist" ~ "ARD",
model == "RegType_magaloni_EA_hist" ~ "AoW"
))
plotmodels2$model <- plotmodels2$model2
plotmodels2 <- plotmodels2%>%mutate(term2 = case_when(
term == "under5" ~ "Under-5 Mortality",
term == "infant" ~ "Infant Mortality",
term == "life" ~ "Life Expectancy",
term == "literacy_original" ~ "Literacy",
term == "schooling2" ~ "Schooling",
term == "lit_equ" ~ "Literacy Equality",
term == "school_equ" ~ "Schooling Equality"))
plotmodels2$term <- plotmodels2$term2
plotmodels2<- plotmodels2 %>% mutate ( conf.low_95 = estimate - 1.96 *  std.error, conf.high_95 = estimate + 1.96 * std.error,
conf.low_90 = estimate - 1.64 *  std.error, conf.high_90 = estimate + 1.64 * std.error) %>% as_tibble()
plotmodels2$bla <- "Coef"
plotmodels2$type<- "Regime History"
plotframe <- rbind(plotmodels, plotmodels2)
names(plotmodels)
names(plotmodels2)
## load packages and data
pacman::p_load(estimatr, tidyverse, texreg, dotwhisker, data.table)
load("Data/Replication/Miller/Miller_Replication_Ready.rda")
## prepare depvar, indepvar combinations
depvars <- c("infant", "under5", "life", "literacy_original", "schooling2", "lit_equ", "school_equ")
rxdepvars <- c("rx_infant", "rx_under5", "rx_life", "rx_literacy_original", "rx_schooling2", "rx_lit_equ", "rx_school_equ")
indepvars <- c("ea" , "dem",
"RegType_lied_EA", "RegType_lied_DEM",
"RegType_RoW_EA", "RegType_RoW_DEM",
"Politytype_Anocracy", "Politytype_Democracy",
"status_fh_PF", "status_fh_F",
"HTW_RegType_MP_Autocracy", "HTW_RegType_Democracy",
"RegType_magaloni_EA", "RegType_magaloni_DEM",
"AnckarRegtype_MP_Autocracy", "AnckarRegtype_Democracy")
controls <- c("aid", "loggdp",  "gdp_grow", "gini2",  "resourcesdep_hm",
"communist", "urban_cow", "ELF", "lnpop", "violence_domestic")
## run all models
a <- seq(1,15 , by = 2)
models <- list()
for (i in 1:length(depvars)) {
outcome <- depvars[i]
rx <- rxdepvars[i]
for (j in 1:8) {
print(paste0("Running Model " , outcome,"_model_",j, ", you bastard!"))
indepvar <- indepvars[c(a[j],a[j]+1)]
formula <- as.formula(paste(outcome, "~",  paste(indepvar, collapse = "+"), "+", rx, "+", paste(controls, collapse = "+")))
models[[paste0(outcome,"_model_", j)]] <- lm_robust(formula, data = df, fixed_effects = year, clusters = ccode, se_type = "stata")
}
}
submodels <- list()
for (i in 1:length(models)){
submodels[[paste0("sub_", models[i])]] <- tidy(models[[i]]) %>%
filter(term %in% c("ea", "RegType_lied_EA", "RegType_RoW_EA", "Politytype_Anocracy", "status_fh_PF", "AnckarRegtype_MP_Autocracy", "HTW_RegType_MP_Autocracy", "RegType_magaloni_EA")) %>%
mutate(model = names(models)[i])
}
plotmodels <- submodels %>%
rbindlist %>%
as.data.frame
rm(submodels)
plotmodels$term2 <- plotmodels$term
plotmodels$model2 <- plotmodels$model
plotmodels$term <- plotmodels$outcome
plotmodels$model <- plotmodels$term2
unique(plotmodels$term)
plotmodels <- plotmodels%>%mutate(model2 = case_when(
model == "ea" ~ "EA Original",
model == "RegType_lied_EA" ~ "LIED",
model == "RegType_RoW_EA" ~ "RoW",
model == "Politytype_Anocracy" ~ "Polity",
model == "status_fh_PF" ~ "FH",
model == "AnckarRegtype_MP_Autocracy" ~ "CPR",
model == "HTW_RegType_MP_Autocracy" ~ "ARD",
model == "RegType_magaloni_EA" ~ "AoW"))
plotmodels$model <- plotmodels$model2
plotmodels <- plotmodels%>%mutate(term2 = case_when(
term == "under5" ~ "Under-5 Mortality",
term == "infant" ~ "Infant Mortality",
term == "life" ~ "Life Expectancy",
term == "literacy_original" ~ "Literacy",
term == "schooling2" ~ "Schooling",
term == "lit_equ" ~ "Literacy Equality",
term == "school_equ" ~ "Schooling Equality"))
plotmodels$term <- plotmodels$term2
## New plot
plotmodels<- plotmodels %>% mutate ( conf.low_95 = estimate - 1.96 *  std.error, conf.high_95 = estimate + 1.96 * std.error,
conf.low_90 = estimate - 1.64 *  std.error, conf.high_90 = estimate + 1.64 * std.error) %>% as_tibble()
### add regime history
indepvars <- c("ea_avg" , "dem_avg",
"RegType_lied_EA_hist", "RegType_lied_DEM_hist",
"RegType_RoW_EA_hist", "RegType_RoW_DEM_hist",
"Politytype_Anocracy_hist", "Politytype_Democracy_hist",
"status_fh_PF_hist", "status_fh_F_hist",
"HTW_RegType_MP_Autocracy_hist", "HTW_RegType_Democracy_hist",
"RegType_magaloni_EA_hist", "RegType_magaloni_DEM_hist",
"AnckarRegtype_MP_Autocracy_hist", "AnckarRegtype_Democracy_hist"
)
depvars <- c("infant", "under5", "life", "literacy_original", "schooling2", "lit_equ", "school_equ")
rxdepvars <- c("rx_infant", "rx_under5", "rx_life", "rx_literacy_original", "rx_schooling2", "rx_lit_equ", "rx_school_equ")
controls <- c("aid", "loggdp",  "gdp_grow", "gini2",  "resourcesdep_hm",
"communist", "urban_cow", "ELF", "lnpop", "violence_domestic")
a <- seq(1,15 , by = 2)
models <- list()
for (i in 1:length(depvars)) {
outcome <- depvars[i]
rx <- rxdepvars[i]
for (j in 1:8) {
print(paste0("Running Model " , outcome,"_model_",j, ", you bastard!"))
indepvar <- indepvars[c(a[j],a[j]+1)]
formula <- as.formula(paste(outcome, "~",  paste(indepvar, collapse = "+"), "+", rx, "+", paste(controls, collapse = "+")))
models[[paste0(outcome,"_model_", j)]] <- lm_robust(formula, data = df, fixed_effects = year, clusters = ccode, se_type = "stata")
}
}
submodels <- list()
for (i in 1:length(models)){
submodels[[paste0("sub_", models[i])]] <- tidy(models[[i]]) %>%
filter(term %in% c("ea_avg", "RegType_lied_EA_hist", "RegType_RoW_EA_hist", "Politytype_Anocracy_hist", "status_fh_PF_hist", "AnckarRegtype_MP_Autocracy_hist", "HTW_RegType_MP_Autocracy_hist", "RegType_magaloni_EA_hist")) %>%
mutate(model = names(models)[i])
}
plotmodels2 <- submodels %>%
rbindlist %>%
as.data.frame
rm(submodels)
plotmodels2$term2 <- plotmodels2$term
plotmodels2$model2 <- plotmodels2$model
plotmodels2$term <- plotmodels2$outcome
plotmodels2$model <- plotmodels2$term2
unique(plotmodels2$term)
plotmodels2 <- plotmodels2%>%mutate(model2 = case_when(
model == "ea_avg" ~ "EA Original",
model == "RegType_lied_EA_hist" ~ "LIED",
model == "RegType_RoW_EA_hist" ~ "RoW",
model == "Politytype_Anocracy_hist" ~ "Polity",
model == "status_fh_PF_hist" ~ "FH",
model == "AnckarRegtype_MP_Autocracy_hist" ~ "CPR",
model == "HTW_RegType_MP_Autocracy_hist" ~ "ARD",
model == "RegType_magaloni_EA_hist" ~ "AoW"
))
plotmodels2$model <- plotmodels2$model2
plotmodels2 <- plotmodels2%>%mutate(term2 = case_when(
term == "under5" ~ "Under-5 Mortality",
term == "infant" ~ "Infant Mortality",
term == "life" ~ "Life Expectancy",
term == "literacy_original" ~ "Literacy",
term == "schooling2" ~ "Schooling",
term == "lit_equ" ~ "Literacy Equality",
term == "school_equ" ~ "Schooling Equality"))
plotmodels2$term <- plotmodels2$term2
plotmodels2<- plotmodels2 %>% mutate ( conf.low_95 = estimate - 1.96 *  std.error, conf.high_95 = estimate + 1.96 * std.error,
conf.low_90 = estimate - 1.64 *  std.error, conf.high_90 = estimate + 1.64 * std.error) %>% as_tibble()
plotmodels$type <- "Regime Dummy"
plotmodels2$type<- "Regime History"
names(plotmodels)
names(plotmodels2)
plotframe <- rbind(plotmodels, plotmodels2)
plotframe$term <- fct_rev(factor(plotframe$term, levels=unique(plotframe$term)))
plotframe$model <- fct_rev(factor(plotframe$model, levels=unique(plotframe$model)))
unique(plotframe$term)
### Make Figure K1
plotframe %>%
filter(term %in% c("Infant Mortality", "Life Expectancy", "Schooling", "Schooling Equality"))%>%
ggplot(aes(x=bla, y = estimate, shape = model)) +
geom_hline(yintercept = 0,
colour = gray(1/2), lty = 2) +
geom_linerange(aes(x = bla,
ymin = conf.low_95,
ymax = conf.high_95), position = position_dodge(width = 1/2), alpha = .7, color = "grey40") +
geom_linerange(aes(x = bla,
ymin = conf.low_90,
ymax = conf.high_90), position = position_dodge(width = 1/2), linewidth = 1, alpha = .7, color = "grey40")   +
geom_point(aes(x = bla,
y = estimate), position = position_dodge(width = 1/2), color = "black", size = 4) +
ggtitle("") + ylab ("") + xlab("") +  guides(shape = guide_legend(reverse=TRUE)) +
coord_flip()  + #scale_y_continuous(breaks = 0) +
theme_classic(base_size = 20) + theme( axis.text.y=element_blank(), axis.ticks.y=element_blank()) +
labs(shape="Measure")  + scale_shape_manual(values = c(56:49)) +  facet_grid(vars(type), vars(fct_rev(term)), scales = "free")
## load packages and data
pacman::p_load(estimatr, tidyverse, texreg, dotwhisker, data.table)
load("Data/Replication/Miller/Miller_Replication_Ready.rda")
## prepare depvar, indepvar combinations
depvars <- c("infant", "under5", "life", "literacy_original", "schooling2", "lit_equ", "school_equ")
rxdepvars <- c("rx_infant", "rx_under5", "rx_life", "rx_literacy_original", "rx_schooling2", "rx_lit_equ", "rx_school_equ")
indepvars <- c("ea" , "dem",
"RegType_lied_EA", "RegType_lied_DEM",
"RegType_RoW_EA", "RegType_RoW_DEM",
"Politytype_Anocracy", "Politytype_Democracy",
"status_fh_PF", "status_fh_F",
"HTW_RegType_MP_Autocracy", "HTW_RegType_Democracy",
"RegType_magaloni_EA", "RegType_magaloni_DEM",
"AnckarRegtype_MP_Autocracy", "AnckarRegtype_Democracy")
controls <- c("aid", "loggdp",  "gdp_grow", "gini2",  "resourcesdep_hm",
"communist", "urban_cow", "ELF", "lnpop", "violence_domestic")
## run all models
a <- seq(1,15 , by = 2)
models <- list()
for (i in 1:length(depvars)) {
outcome <- depvars[i]
rx <- rxdepvars[i]
for (j in 1:8) {
print(paste0("Running Model " , outcome,"_model_",j, ", you bastard!"))
indepvar <- indepvars[c(a[j],a[j]+1)]
formula <- as.formula(paste(outcome, "~",  paste(indepvar, collapse = "+"), "+", rx, "+", paste(controls, collapse = "+")))
models[[paste0(outcome,"_model_", j)]] <- lm_robust(formula, data = df, fixed_effects = year, clusters = ccode, se_type = "stata")
}
}
submodels <- list()
for (i in 1:length(models)){
submodels[[paste0("sub_", models[i])]] <- tidy(models[[i]]) %>%
filter(term %in% c("ea", "RegType_lied_EA", "RegType_RoW_EA", "Politytype_Anocracy", "status_fh_PF", "AnckarRegtype_MP_Autocracy", "HTW_RegType_MP_Autocracy", "RegType_magaloni_EA")) %>%
mutate(model = names(models)[i])
}
plotmodels <- submodels %>%
rbindlist %>%
as.data.frame
rm(submodels)
plotmodels$term2 <- plotmodels$term
plotmodels$model2 <- plotmodels$model
plotmodels$term <- plotmodels$outcome
plotmodels$model <- plotmodels$term2
unique(plotmodels$term)
plotmodels <- plotmodels%>%mutate(model2 = case_when(
model == "ea" ~ "EA Original",
model == "RegType_lied_EA" ~ "LIED",
model == "RegType_RoW_EA" ~ "RoW",
model == "Politytype_Anocracy" ~ "Polity",
model == "status_fh_PF" ~ "FH",
model == "AnckarRegtype_MP_Autocracy" ~ "CPR",
model == "HTW_RegType_MP_Autocracy" ~ "ARD",
model == "RegType_magaloni_EA" ~ "AoW"))
plotmodels$model <- plotmodels$model2
plotmodels <- plotmodels%>%mutate(term2 = case_when(
term == "under5" ~ "Under-5 Mortality",
term == "infant" ~ "Infant Mortality",
term == "life" ~ "Life Expectancy",
term == "literacy_original" ~ "Literacy",
term == "schooling2" ~ "Schooling",
term == "lit_equ" ~ "Literacy Equality",
term == "school_equ" ~ "Schooling Equality"))
plotmodels$term <- plotmodels$term2
## New plot
plotmodels<- plotmodels %>% mutate ( conf.low_95 = estimate - 1.96 *  std.error, conf.high_95 = estimate + 1.96 * std.error,
conf.low_90 = estimate - 1.64 *  std.error, conf.high_90 = estimate + 1.64 * std.error) %>% as_tibble()
### add regime history
indepvars <- c("ea_avg" , "dem_avg",
"RegType_lied_EA_hist", "RegType_lied_DEM_hist",
"RegType_RoW_EA_hist", "RegType_RoW_DEM_hist",
"Politytype_Anocracy_hist", "Politytype_Democracy_hist",
"status_fh_PF_hist", "status_fh_F_hist",
"HTW_RegType_MP_Autocracy_hist", "HTW_RegType_Democracy_hist",
"RegType_magaloni_EA_hist", "RegType_magaloni_DEM_hist",
"AnckarRegtype_MP_Autocracy_hist", "AnckarRegtype_Democracy_hist"
)
depvars <- c("infant", "under5", "life", "literacy_original", "schooling2", "lit_equ", "school_equ")
rxdepvars <- c("rx_infant", "rx_under5", "rx_life", "rx_literacy_original", "rx_schooling2", "rx_lit_equ", "rx_school_equ")
controls <- c("aid", "loggdp",  "gdp_grow", "gini2",  "resourcesdep_hm",
"communist", "urban_cow", "ELF", "lnpop", "violence_domestic")
a <- seq(1,15 , by = 2)
models <- list()
for (i in 1:length(depvars)) {
outcome <- depvars[i]
rx <- rxdepvars[i]
for (j in 1:8) {
print(paste0("Running Model " , outcome,"_model_",j, ", you bastard!"))
indepvar <- indepvars[c(a[j],a[j]+1)]
formula <- as.formula(paste(outcome, "~",  paste(indepvar, collapse = "+"), "+", rx, "+", paste(controls, collapse = "+")))
models[[paste0(outcome,"_model_", j)]] <- lm_robust(formula, data = df, fixed_effects = year, clusters = ccode, se_type = "stata")
}
}
submodels <- list()
for (i in 1:length(models)){
submodels[[paste0("sub_", models[i])]] <- tidy(models[[i]]) %>%
filter(term %in% c("ea_avg", "RegType_lied_EA_hist", "RegType_RoW_EA_hist", "Politytype_Anocracy_hist", "status_fh_PF_hist", "AnckarRegtype_MP_Autocracy_hist", "HTW_RegType_MP_Autocracy_hist", "RegType_magaloni_EA_hist")) %>%
mutate(model = names(models)[i])
}
plotmodels2 <- submodels %>%
rbindlist %>%
as.data.frame
rm(submodels)
plotmodels2$term2 <- plotmodels2$term
plotmodels2$model2 <- plotmodels2$model
plotmodels2$term <- plotmodels2$outcome
plotmodels2$model <- plotmodels2$term2
unique(plotmodels2$term)
plotmodels2 <- plotmodels2%>%mutate(model2 = case_when(
model == "ea_avg" ~ "EA Original",
model == "RegType_lied_EA_hist" ~ "LIED",
model == "RegType_RoW_EA_hist" ~ "RoW",
model == "Politytype_Anocracy_hist" ~ "Polity",
model == "status_fh_PF_hist" ~ "FH",
model == "AnckarRegtype_MP_Autocracy_hist" ~ "CPR",
model == "HTW_RegType_MP_Autocracy_hist" ~ "ARD",
model == "RegType_magaloni_EA_hist" ~ "AoW"
))
plotmodels2$model <- plotmodels2$model2
plotmodels2 <- plotmodels2%>%mutate(term2 = case_when(
term == "under5" ~ "Under-5 Mortality",
term == "infant" ~ "Infant Mortality",
term == "life" ~ "Life Expectancy",
term == "literacy_original" ~ "Literacy",
term == "schooling2" ~ "Schooling",
term == "lit_equ" ~ "Literacy Equality",
term == "school_equ" ~ "Schooling Equality"))
plotmodels2$term <- plotmodels2$term2
plotmodels2<- plotmodels2 %>% mutate ( conf.low_95 = estimate - 1.96 *  std.error, conf.high_95 = estimate + 1.96 * std.error,
conf.low_90 = estimate - 1.64 *  std.error, conf.high_90 = estimate + 1.64 * std.error) %>% as_tibble()
plotmodels2$bla <- "Coef"
plotmodels2$type<- "Regime History"
plotmodels$bla <- "Coef"
plotmodels$type<- "Regime Dummy"
names(plotmodels)
names(plotmodels)
plotframe <- rbind(plotmodels, plotmodels2)
plotframe$term <- fct_rev(factor(plotframe$term, levels=unique(plotframe$term)))
plotframe$model <- fct_rev(factor(plotframe$model, levels=unique(plotframe$model)))
unique(plotframe$term)
### Make Figure K1
plotframe %>%
filter(term %in% c("Infant Mortality", "Life Expectancy", "Schooling", "Schooling Equality"))%>%
ggplot(aes(x=bla, y = estimate, shape = model)) +
geom_hline(yintercept = 0,
colour = gray(1/2), lty = 2) +
geom_linerange(aes(x = bla,
ymin = conf.low_95,
ymax = conf.high_95), position = position_dodge(width = 1/2), alpha = .7, color = "grey40") +
geom_linerange(aes(x = bla,
ymin = conf.low_90,
ymax = conf.high_90), position = position_dodge(width = 1/2), linewidth = 1, alpha = .7, color = "grey40")   +
geom_point(aes(x = bla,
y = estimate), position = position_dodge(width = 1/2), color = "black", size = 4) +
ggtitle("") + ylab ("") + xlab("") +  guides(shape = guide_legend(reverse=TRUE)) +
coord_flip()  + #scale_y_continuous(breaks = 0) +
theme_classic(base_size = 20) + theme( axis.text.y=element_blank(), axis.ticks.y=element_blank()) +
labs(shape="Measure")  + scale_shape_manual(values = c(56:49)) +  facet_grid(vars(type), vars(fct_rev(term)), scales = "free")
## load packages and data
pacman::p_load(tidyverse, corrr, knitr, kableExtra, haven, fixest, dotwhisker, RColorBrewer, broom)
load("Data/Replication/Kim/Kim_Replication_Ready.rda")
### analysis
#Original Base Regressions:
names(data)
m1 <- femlm(Flied_EA ~ navco3yr_sum + navco3yr_other_sum + ln_EA_yrs + yearly, cluster =  "ccode", data=data%>%filter(sample == 1 ), family = "logit") %>% tidy() %>%mutate(model = "Original")
m2 <- femlm(F_RegType_lied_EA ~ navco3yr_sum + navco3yr_other_sum + ln_RegType_lied_n_period_duration + yearly, cluster =  "ccode", data=data%>%filter(RegType_lied_CA == 1 ), family = "logit") %>% tidy() %>%mutate(model = "LIED")
m3 <- femlm(F_RegType_RoW_EA ~ navco3yr_sum + navco3yr_other_sum + ln_RegType_RoW_n_period_duration + yearly, cluster =  "ccode", data=data%>%filter(RegType_RoW_CA == 1 ), family = "logit") %>% tidy() %>%mutate(model = "RoW")
m4 <- femlm(F_Politytype_Anocracy ~ navco3yr_sum + navco3yr_other_sum + ln_Politytype_n_period_duration + yearly, cluster =  "ccode", data=data%>%filter(Politytype_Autocracy == 1 ), family = "logit") %>% tidy() %>%mutate(model = "Polity")
m5 <- femlm(F_status_fh_PF ~ navco3yr_sum + navco3yr_other_sum + ln_fh_status_n_period_duration + yearly, cluster =  "ccode", data=data%>%filter(status_fh_NF == 1 ), family = "logit") %>% tidy() %>%mutate(model = "FH")
m6 <- femlm(F_AnckarRegtype_MP_Autocracy ~ navco3yr_sum + navco3yr_other_sum + ln_AnckarRegtype_n_period_duration + yearly, cluster =  "ccode", data=data%>%filter(AnckarRegtype_Non_MP_Autocracy == 1 ), family = "logit") %>% tidy() %>%mutate(model = "CPR")
m7 <- femlm(F_HTW_RegType_MP_Autocracy ~ navco3yr_sum + navco3yr_other_sum + ln_HTW_RegType_n_period_duration + yearly, cluster =  "ccode", data=data%>%filter(HTW_RegType_Non_MP_Autocracy == 1 ), family = "logit") %>% tidy() %>%mutate(model = "ARD")
m8 <- femlm(F_RegType_magaloni_EA ~ navco3yr_sum + navco3yr_other_sum + ln_RegType_magaloni_n_period_duration + yearly, cluster =  "ccode", data=data%>%filter(RegType_magaloni_CA == 1 ), family = "logit") %>% tidy() %>%mutate(model = "AoW")
summary(m1)
summary(m2)
summary(m3)
summary(m4)
summary(m5)
summary(m6)
summary(m7)
summary(m8)
res <-  rbind(m1,m2,m3, m4,m5,m7,m8,m6)
res_basic <- res %>% mutate(spec = "Base Models")
###Full Regressions
m1 <- femlm(Flied_EA ~ navco3yr_sum + navco3yr_other_sum +
ln_EA_yrs + n5_lied_demo + n5_lied_EA +
postcold*lnwdi_aid_pc + v2x_libdem + milper_capita + elit_unrest + irreg3yrs + lngdppc + oneyrgrowth + yearly,
cluster=  "ccode", data=data%>%filter(sample == 1 ), family = "logit")
summary(m1)
m2 <- femlm(F_RegType_lied_EA ~ navco3yr_sum + navco3yr_other_sum +
ln_RegType_lied_n_period_duration + neigh_DEM_lied + neigh_EA_lied +
postcold*lnwdi_aid_pc + v2x_libdem + milper_capita + elit_unrest + irreg3yrs + lngdppc + oneyrgrowth + yearly,
cluster =  "ccode", data=data%>%filter(RegType_lied_CA == 1), family = "logit")
summary(m2)
m3 <- femlm(F_RegType_RoW_EA ~ navco3yr_sum + navco3yr_other_sum +
ln_RegType_RoW_n_period_duration + neigh_DEM_RoW + neigh_EA_RoW +
postcold*lnwdi_aid_pc + v2x_libdem + milper_capita + elit_unrest + irreg3yrs + lngdppc + oneyrgrowth + yearly,
cluster =  "ccode", data=data%>%filter(RegType_RoW_CA == 1), family = "logit")
summary(m3)
m4 <- femlm(F_Politytype_Anocracy ~ navco3yr_sum + navco3yr_other_sum +
ln_Politytype_n_period_duration + neigh_DEM_Polity + neigh_EA_Polity +
postcold*lnwdi_aid_pc + v2x_libdem + milper_capita + elit_unrest + irreg3yrs + lngdppc + oneyrgrowth + yearly,
cluster =  "ccode", data=data%>%filter(RegType_RoW_CA == 1), family = "logit")
summary(m4)
m5 <- femlm(F_status_fh_PF ~ navco3yr_sum + navco3yr_other_sum +
ln_fh_status_n_period_duration + neigh_DEM_FH + neigh_EA_FH +
postcold*lnwdi_aid_pc + v2x_libdem + milper_capita + elit_unrest + irreg3yrs + lngdppc + oneyrgrowth + yearly,
cluster =  "ccode", data=data%>%filter(status_fh_NF == 1), family = "logit")
summary(m5)
m6 <- femlm(F_AnckarRegtype_MP_Autocracy ~ navco3yr_sum + navco3yr_other_sum +
ln_AnckarRegtype_n_period_duration + neigh_DEM_AF + neigh_EA_AF+
postcold*lnwdi_aid_pc + v2x_libdem + milper_capita + elit_unrest + irreg3yrs + lngdppc + oneyrgrowth + yearly,
cluster =  "ccode", data=data%>%filter(AnckarRegtype_Non_MP_Autocracy == 1), family = "logit")
summary(m6)
m7 <- femlm(F_HTW_RegType_MP_Autocracy ~ navco3yr_sum + navco3yr_other_sum +
ln_AnckarRegtype_n_period_duration + neigh_DEM_HTW + neigh_EA_HTW+
postcold*lnwdi_aid_pc + v2x_libdem + milper_capita + elit_unrest + irreg3yrs + lngdppc + oneyrgrowth + yearly,
cluster =  "ccode", data=data%>%filter(HTW_RegType_Non_MP_Autocracy == 1), family = "logit")
summary(m7)
m8 <- femlm(F_RegType_magaloni_EA ~ navco3yr_sum + navco3yr_other_sum +
ln_RegType_magaloni_n_period_duration + neigh_DEM_AWD + neigh_EA_AWD+
postcold*lnwdi_aid_pc + v2x_libdem + milper_capita + elit_unrest + irreg3yrs + lngdppc + oneyrgrowth + yearly,
cluster =  "ccode", data=data%>%filter(RegType_magaloni_CA == 1), family = "logit")
summary(m8)
m1 <- m1%>% tidy() %>%mutate(model = "Original")
m2 <- m2%>% tidy() %>%mutate(model = "LIED")
m3 <- m3%>% tidy() %>%mutate(model = "RoW")
m4 <- m4%>% tidy() %>%mutate(model = "Polity")
m5 <- m5%>% tidy() %>%mutate(model = "FH")
m6 <- m6%>% tidy() %>%mutate(model = "CPR")
m7 <- m7%>% tidy() %>%mutate(model = "ARD")
m8 <- m8%>% tidy() %>%mutate(model = "AoW")
res <-  rbind(m1,m2,m3, m4,m5,m7,m8,m6)
res$term <- ifelse(res$term == "navco3yr_sum", "Anti-Regime Uprising", res$term)
res$term <- ifelse(res$term == "navco3yr_other_sum", "Other Uprising", res$term)
res_full <- rbind(res_basic, res %>% mutate(spec = "Full Set of Controls"))
res_full$term <- ifelse(res_full$term == "navco3yr_sum", "Anti-Regime Uprising", res_full$term)
res_full$term <- ifelse(res_full$term == "navco3yr_other_sum", "Other Uprising", res_full$term)
res_full <- res_full %>% mutate ( conf.low_95 = estimate - 1.96 *  std.error,
conf.high_95 = estimate + 1.96 * std.error,
conf.low_90 = estimate - 1.64 *  std.error,
conf.high_90 = estimate + 1.64 * std.error)
res_full$Measure <- res_full$model
res_full$Measure <- factor(res_full$Measure,  levels=c("Original", "LIED", "RoW", "Polity", "FH", "ARD", "AoW", "CPR"))
res_full$Measure <- fct_rev(res_full$Measure)
res_full$spec <- as.factor(res_full$spec)
levels(res_full$spec) <- c("Model 1", "Model 3")
### Make Figure K2
ggplot(res_full%>%filter(term %in% c("Anti-Regime Uprising", "Other Uprising" )) %>% mutate(term = fct_rev(term)), #%>%mutate(Measure = fct_rev(model)),
aes(x = term, y = estimate, shape = Measure)) +
geom_hline(yintercept = 0,
colour = gray(1/2), lty = 2) +
geom_linerange(aes(x = term,
ymin = conf.low_95,
ymax = conf.high_95), position = position_dodge(width = 1/2), alpha = .7, color = "grey40")  +
geom_linerange(aes(x = term,
ymin = conf.low_90,
ymax = conf.high_90), position = position_dodge(width = 1/2), linewidth = 1, alpha = .7, color = "grey40")  +
geom_point(aes(x = term,
y = estimate), size = 4, position = position_dodge(width = 1/2), color = "black") +
ggtitle("") + ylab ("") + xlab("") + facet_wrap(~spec) +
coord_flip()  +
theme_classic(base_size = 20) + theme(text=element_text(size=20)) +  guides(shape = guide_legend(reverse=T), title = "Measure") +
theme(legend.position = "right") + scale_shape_manual(values = c(56:49))
